//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Diagnostics.Contracts;
using System.Reflection;
using OpenLS.Core.Notification;
using OpenLS.Core.Serialization;
using OpenLS.Drawing;
using System.ComponentModel;

namespace OpenLS.Chart
{
    public class Marker : ViewModelBase, IOfficeXmlSerializable, IShape
    {
        private int _size = DefaultSize;
        private ShapeProperties spPr;
        private MarkerStyle? symbol;

        public MarkerStyle? Symbol
        {
            get { return symbol; }
            set { symbol = value;notifyPropertyChanged("Symbol"); }
        }

        public int Size
        {
            get { return _size; }
            set
            {
                if (value < 0)
                    throw new ArgumentException("value");
                 _size = value;notifyPropertyChanged("Size");
            }
        }

        public ShapeProperties ShapeProperties
        {
            get { return spPr; }
            set { spPr = value; notifyPropertyChanged("ShapeProperties"); }
        }

        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (var c = context.Read("marker"))
            {
                Symbol = c.ReadOptionalElementEnumAttribute<MarkerStyle>("symbol");
                _size = c.ReadOptionalElementIntegerAttribute("size", 5);
                spPr = c.ReadOptionalElement<ShapeProperties>("spPr");
                c.WarnIf("crtExt");
            }
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write("marker"))
            {
                c.WriteOptionalElementEnumAttribute("symbol", Symbol);
                c.WriteOptionalElementIntegerAttribute("size", _size, 5);
                c.WriteOptionalElement(spPr);
                c.WarnIf("crtExt");
            }
        }

        #endregion

        internal static int DefaultSize
        {
            get{ return 7;}
        }
    }
}